::%1 - path to solution root dir
::%2 - configruation name - Debug or Release
::%3 - platform name      - x86, x64, AnyCPU
::%4 - optional path to additional exclude file

set SolutionDir=%~1
set Configuration=%~2
set Platform=%~3
set Exclude=%~4

echo Working with Configuration=%Configuration% Platform=%Platform%

::this is folder where all files required to build setup should be placed
set SetupSourceDir=%SolutionDir%\bin\Setup\Source

::this is folder where results of building specific configuration+platform are
set OutputDir=%SolutionDir%\bin\%Platform%\%Configuration%

::path to Setup project folder
set SetupProjectDir=%SolutionDir%\Setup

::step 1 - clean up Setup Source dir
echo Removing old Source directory
rmdir /S /Q "%SetupSourceDir%"

echo Creating new Source directory
mkdir "%SetupSourceDir%"

::step 2 - gathering all essetntial files for setup

if "%Exclude%." EQU "." (
set Exclude=%SetupProjectDir%\exclude.txt 
) ELSE (
set Exclude=%Exclude%+%SetupProjectDir%\exclude.txt 
)

echo Copying files from output folder
xcopy "%OutputDir%\*" "%SetupSourceDir%" /S /E /Y /EXCLUDE:%Exclude%

echo Done.